using System;
using System.Collections.Generic;
using System.Text;

namespace XHTMLPoink
{
    public enum POSTEncType
    {
        MultipartFormData,
        URLEncoded,
        PlainText
    }

    public class XHTMLDocument
    {
        string sHeader;
        string sBody;
        string sFooter;

        bool bFirstPara;

        public XHTMLDocument(string Title)
        {
            sHeader = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
            sHeader += "\r\n\r\n\t<html>\r\n\r\n\t\t<head>\r\n\t\t\t<title>" + Title.Replace('<', '!').Replace('>', '!').Trim() + "</title>\r\n\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"/files/theme/normal.css\" />";
            sHeader += "\r\n\t\t</head>\r\n\r\n\t\t<body>\r\n\r\n";

            sBody = "";

            sFooter = "\t\t</body>\r\n\r\n\t</html>\r\n";
            
            bFirstPara = true;
        }

        ~XHTMLDocument()
        {
            sHeader = "";
            sBody = "";
            sFooter = "";
            bFirstPara = true;
        }

        public string GimmeTehCodez()
        {
            return sHeader + sBody + sFooter;
        }


        public void AddHeading(int HNumber, string Content)
        {
            sBody += "\t\t\t<h" + HNumber.ToString() + ">" + Content + "</h" + HNumber.ToString() + ">\r\n\r\n";
        }

        public void BeginParagraph()
        {
            if (!bFirstPara)
                sBody += "\t\t\t<p>\r\n";
        }

        public void EndParagraph()
        {
            if (bFirstPara)
            {
                bFirstPara = false;
                sBody += "\r\n";
            }
            else
                sBody += "\t\t\t</p>\r\n\r\n";
        }

        public void BeginDiv(string Class)
        {
            sBody += "\t\t\t<div class=\"" + Class + "\">\r\n";
        }

        public void EndDiv()
        {
            sBody += "\t\t\t</div>\r\n";
        }

        public void AddLineBreak()
        {
            sBody += "\t\t\t\t<br />\r\n";
        }

        public void AddText(string Text)
        {
            sBody += "\t\t\t\t" + Text.Replace("\r\n", "<br />") + "\r\n";
        }

        public void AddImage(string ImageAddress, string Alt)
        {
            sBody += "\t\t\t<img src=\"" + ImageAddress + "\" alt=\"" + Alt + "\" />\r\n";
        }
    }
}
